<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!--公用头部-->
    <th:block th:replace="common/head::commonHead('${table.comment}修改-小邑')" />
    <style>
    </style>
</head>
<!--公用js-->
<th:block th:replace="common/head::commonJs"/>
<body marginwidth="0" marginheight="0">
<form class="layui-form" action="" lay-filter="${lowerEntityName}Form">
<div class="layui-fluid  layui-fluid-btn">
<#if table.fields?? && (table.fields?size > 0) >
    <div class="layui-col-md12">
        <div class="layui-card" style="margin: 10px;">
            <div class="layui-card-body">
                    <#list table.fields as field>
                    <#if field.keyFlag>
                    <input name="${field.propertyName}" type="text" style="display: none">
                    <#else>
                    <div class="layui-form-item">
                        <label class="layui-form-label layui-form-required">${field.comment}</label>
                        <div class="layui-input-block">
                            <input type="text" name="${field.propertyName}" id="${field.propertyName}" lay-verify="required" placeholder="请输入${field.comment}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    </#if>
                    </#list>
                    <div class="form-group-bottom">
                        <button class="xy-btn xy-btn-primary subCheckBtn" lay-submit lay-filter="formBtn">提交</button>
                        <button type="reset" class="xy-btn">重置</button>
                    </div>
            </div>
        </div>
    </div>
</div>
</form>
</#if>
<script>
    layui.use(['layer','jquery','form','notice'], function() {
        var $ = layui.jquery
            ,form = layui.form
            ,notice = layui.notice
            ,layer = layui.layer;

        //获取详情信息，填充表单
        sendAjaxPostToError(
            basePath + '/${lowerEntityName}/detail${entity}',
            {
                ${keyPropertyName}: utils.request.getQueryString('${keyPropertyName}')
            },
            function (res){
                if (res.success){
                    form.val('${lowerEntityName}Form', res.data);
                }else {
                    top.layui.notice.msg(res.msg ,{icon: 2,position:"topCenter"});
                }
            },
            function (e){
                top.layui.notice.msg("获取数据失败~" ,{icon: 2,position:"topCenter"});
            }
        )

        //监听提交
        form.on('submit(formBtn)', function(data) {
            var loadIndex = null;
            checkSubBtn(1);
            sendAjaxPostToCallback(
                basePath + '/${lowerEntityName}/edit${entity}',
                data.field,
                function (result){
                    if (result.success){
                        // 提示信息
                        top.layui.notice.msg(result.msg ,{icon: 1,position:"topCenter"});
                        // 获取当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        // 关闭弹窗
                        parent.layer.close(index);
                        // 重载表格
                        parent.layui.table.reload('${lowerEntityName}Table',{});
                    }else{
                        checkSubBtn(2);
                        top.layui.notice.msg(result.msg ,{icon: 2,position:"topCenter"});
                    }
                },
                function (data) {
                    checkSubBtn(2);
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)){
                        top.layui.notice.msg(data.msg ,{icon: 2,position:"topCenter"});
                    }else{
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2,position:"topCenter"});
                    }
                },
                function (){
                    loadIndex = layer.load(1);
                },
                function (){
                    layer.close(loadIndex);
                },
            )
            return false;
        });

    });
</script>
</body>
</html>
